cube = {}
cube = {-100,-100,-100,-100, 100,-100, 100, 100,-100, 100,-100,-100,-100,-100, 100,-100, 100, 100, 100, 100, 100, 100,-100, 100}

cube_tri = {}
cube_tri = {1,2,3,3,4,1,5,6,7,7,8,5,5,6,2,2,1,5,8,7,3,3,4,8,2,6,7,7,3,2,1,5,8,8,4,1}






pentagram = {}
pentagram = {0.0000,422.9851,50
,402.2827,130.7096,50
,248.6244,-342.2021,50
,-248.6244,-342.2021,50
,-402.2827,130.7096,50
,207.1796,285.1583,30
,335.2237,-108.9208,30
,0.0000,-352.4750,30
,-335.2237,-108.9208,30
,-207.1796,285.1583,30
,25.6143,344.1525,30
,319.3932,130.7096,30
,335.2237,81.9883,30
,223.0101,-263.3695,30
,181.5654,-293.4809,30
,-181.5654,-293.4809,30
,-223.0101,-263.3695,30
,-335.2237,81.9883,30
,-319.3932,130.7096,30
,-25.6143,344.1525,30
,48.5322,273.6182,30
,170.0976,234.1193,30
,245.2291,130.7096,30
,275.2237,38.3958,30
,275.2237,-89.4256,30
,200.0922,-192.8353,30
,121.5654,-249.8883,30
,0.0000,-289.3873,30
,-121.5654,-249.8883,30
,-200.0922,-192.8353,30
,-275.2237,-89.4256,30
,-275.2237,38.3958,30
,-245.2291,130.7096,30
,-170.0976,234.1193,30
,-48.5322,273.6182,30
,0.0000,228.8210,50
,94.9661,130.7096,50
,217.6217,70.7096,50
,153.6583,-49.9266,50
,134.4976,-185.1201,50
,0.0000,-161.5659,50
,-134.4976,-185.1201,50
,-153.6583,-49.9266,50
,-217.6217,70.7096,50
,-94.9661,130.7096,50
,31.8783,130.7096,50
,114.4612,70.7096,50
,134.1631,10.0734,50
,102.6193,-87.0087,50
,51.0390,-124.4839,50
,-51.0390,-124.4839,50
,-102.6193,-87.0087,50
,-134.1631,10.0734,50
,-114.4612,70.7096,50
,-31.8783,130.7096,50
,51.3735,70.7096,50
,83.1241,-27.0087,50
,0.0000,-87.4018,50
,-83.1241,-27.0087,50
,-51.3735,70.7096,50
,0.0000,422.9851,-50
,402.2827,130.7096,-50
,248.6244,-342.2021,-50
,-248.6244,-342.2021,-50
,-402.2827,130.7096,-50
,207.1796,285.1583,-30
,335.2237,-108.9208,-30
,0.0000,-352.4750,-30
,-335.2237,-108.9208,-30
,-207.1796,285.1583,-30
,25.6143,344.1525,-30
,319.3932,130.7096,-30
,335.2237,81.9883,-30
,223.0101,-263.3695,-30
,181.5654,-293.4809,-30
,-181.5654,-293.4809,-30
,-223.0101,-263.3695,-30
,-335.2237,81.9883,-30
,-319.3932,130.7096,-30
,-25.6143,344.1525,-30
,48.5322,273.6182,-30
,170.0976,234.1193,-30
,245.2291,130.7096,-30
,275.2237,38.3958,-30
,275.2237,-89.4256,-30
,200.0922,-192.8353,-30
,121.5654,-249.8883,-30
,0.0000,-289.3873,-30
,-121.5654,-249.8883,-30
,-200.0922,-192.8353,-30
,-275.2237,-89.4256,-30
,-275.2237,38.3958,-30
,-245.2291,130.7096,-30
,-170.0976,234.1193,-30
,-48.5322,273.6182,-30
,0.0000,228.8210,-50
,94.9661,130.7096,-50
,217.6217,70.7096,-50
,153.6583,-49.9266,-50
,134.4976,-185.1201,-50
,0.0000,-161.5659,-50
,-134.4976,-185.1201,-50
,-153.6583,-49.9266,-50
,-217.6217,70.7096,-50
,-94.9661,130.7096,-50
,31.8783,130.7096,-50
,114.4612,70.7096,-50
,134.1631,10.0734,-50
,102.6193,-87.0087,-50
,51.0390,-124.4839,-50
,-51.0390,-124.4839,-50
,-102.6193,-87.0087,-50
,-134.1631,10.0734,-50
,-114.4612,70.7096,-50
,-31.8783,130.7096,-50
,51.3735,70.7096,-50
,83.1241,-27.0087,-50
,0.0000,-87.4018,-50
,-83.1241,-27.0087,-50
,-51.3735,70.7096,-50}


pentagram_tri = {}
pentagram_tri = {
1,36,45
,1,36,37
,2,37,38
,2,38,39
,3,39,40
,3,40,41
,4,41,42
,4,42,43
,5,44,43
,5,44,45
,36,45,60
,36,37,56
,37,38,56
,38,39,57
,39,40,57
,40,41,58
,41,42,58
,42,43,59
,43,44,59
,44,45,60
,55,56,60
,46,55,56
,47,56,57
,47,48,57
,49,57,58
,49,50,58
,51,58,59
,51,52,59
,53,59,60
,53,54,60
,6,11,21
,6,21,22
,6,22,23
,6,12,23
,7,13,24
,7,24,25
,7,25,26
,7,14,26
,8,15,27
,8,27,28
,8,28,29
,8,16,29
,9,17,30
,9,30,31
,9,31,32
,9,18,32
,10,19,33
,10,33,34
,10,34,35
,10,20,35
,61,96,105
,61,96,97
,62,97,98
,62,98,99
,63,99,100
,63,100,101
,64,101,102
,64,102,103
,65,104,103
,65,104,105
,96,105,120
,96,97,116
,97,98,116
,98,99,117
,99,100,117
,100,101,118
,101,102,118
,102,103,119
,103,104,119
,104,105,120
,115,116,120
,106,115,116
,107,116,117
,107,108,117
,109,117,118
,109,110,118
,111,118,119
,111,112,119
,113,119,120
,113,114,120
,66,71,81
,66,81,82
,66,82,83
,66,72,83
,67,73,84
,67,84,85
,67,85,86
,67,74,86
,68,75,87
,68,87,88
,68,88,89
,68,76,89
,69,77,90
,69,90,91
,69,91,92
,69,78,92
,70,79,93
,70,93,94
,70,94,95
,70,80,95
,1,61,97
,1,37,97
,2,62,97
,2,37,97
,2,39,99
,2,62,99
,3,63,99
,3,39,99
,3,41,101
,3,63,101
,4,64,101
,4,41,101
,4,43,103
,4,64,103
,5,65,103
,5,43,103
,5,45,105
,5,65,105
,1,61,105
,1,45,105
,36,96,106
,36,46,106
,38,98,107
,38,47,107
,38,48,108
,38,98,108
,40,100,109
,40,49,109
,40,50,110
,40,100,110
,42,102,111
,42,51,111
,42,52,112
,42,102,112
,44,104,113
,44,53,113
,44,54,114
,44,104,114
,36,96,115
,36,55,115
,6,11,71
,6,66,71
,6,12,66
,12,66,72
,7,13,73
,7,67,73
,7,14,67
,14,67,74
,8,15,75
,8,68,75
,8,16,68
,16,68,76
,9,17,77
,9,69,77
,9,18,69
,18,69,78
,10,19,79
,10,70,79
,10,20,70
,20,70,80
,21,81,82
,21,22,82
,22,82,83
,22,23,83
,24,84,85
,24,25,85
,25,85,86
,25,26,86
,27,87,88
,27,28,88
,28,88,89
,28,29,89
,30,90,91
,30,31,91
,31,91,92
,31,32,92
,33,93,94
,33,34,94
,34,94,95
,34,35,95
,46,106,115
,47,48,107
,48,107,108
,49,50,109
,50,109,110
,51,52,111
,52,111,112
,53,54,113
,54,113,114
,46,55,115
,56,60,116
,56,116,117
,56,57,117
,57,117,118
,57,58,118
,58,118,119
,58,59,119
,59,119,120
,59,60,120
,60,116,120}

posX = (screenwidth()/2)
posY = (screenheight()/2)
scale = .6
alfa=0
local step=1
actual3Dobject = cube
actualtriangles = cube_tri




function onmainloop ()
        
        clear(0,0,0)
         

         numleft = numkeypress( keyleft() )
         numright = numkeypress( keyright() )
         numup = numkeypress( keyup() )
         numdown = numkeypress( keydown() )


         if numright > 0 then alfa = alfa + step
            if alfa > 360 then alfa = alfa - 360
            end
         end;
         
         if numleft > 0 then alfa = alfa - step
            if alfa < 0 then alfa = alfa + 360
            end        
         end;
         
         if numup > 0 then actual3Dobject = cube
                actualtriangles = cube_tri
         end;
         
         if numdown > 0 then actual3Dobject = pentagram
                actualtriangles = pentagram_tri 
         end;




actual3Dobject = transformation (actual3Dobject,alfa)
projection (actual3Dobject,actualtriangles)
--projection (cube, cube_tri)

         if (mousedown() > 0) then
            quit()
         end
end



function transformation (nodes,alfa)
        local actual = {}
        local alfa_radian = alfa * 0.0174
        local sinalfa = (math.sin (alfa_radian))        
        local cosalfa = (math.cos (alfa_radian))

        local i
                for i = 1, ((table.maxn (nodes))/3) do
                        local x = nodes[i*3-2]
                        local y = nodes[i*3-1]
                        local z = nodes[i*3  ]
                        local xx = x * cosalfa - z * sinalfa
                        local yy = y 
                        local zz = x * sinalfa + z * cosalfa
                        table.insert(actual,(xx))
                        table.insert(actual,(yy))
                        table.insert(actual,(zz))
                end   

return actual
end  -- of transformation


function projection (nodes,triangles)
        local actual = {}
        local i
                for i = 1, ((table.maxn (nodes))/3) do
                        local xx, yy = perspective((nodes[i*3-2]),(nodes[i*3-1]),(nodes[i*3  ]))
                        table.insert(actual,(xx))
                        table.insert(actual,(yy))
                end   
local i
        for i = 1, ((table.maxn (triangles))/3) do
                local x1 = actual[(triangles [i*3-2])*2-1]  -- 1st point X
                local y1 = actual[(triangles [i*3-2])*2  ]  -- 1st point Y
                local x2 = actual[(triangles [i*3-1])*2-1]  -- 2nd point X
                local y2 = actual[(triangles [i*3-1])*2  ]  -- 2nd point X
                local x3 = actual[(triangles [i*3  ])*2-1]  -- 3rd point X
                local y3 = actual[(triangles [i*3  ])*2  ]  -- 3rd point X
                poly(255, 255, 0, x1*scale + posX, y1*scale + posY, x2*scale + posX, y2*scale + posY, x3*scale + posX, y3*scale + posY)

        end   
end -- of projection


function perspective (x,y,z)
        local d=8000
        local k = (d/(d+y))
        local xx = k * x
        local yy = k * y
        return xx,yy
end  -- of perspective